package com.hsnn.medstgmini.pro.base.service.Impl;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.pro.base.dao.WsjDelRelationDao;
import com.hsnn.medstgmini.pro.base.service.WsjDelRelationManager;
import com.hsnn.medstgmini.util.ConstantsUtil;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.Pagination;

/**
 * @category 卫生局配送关系管理
 * @author wangbing
 * @date 2015年11月20日
 */
@Service
public class WsjDelRelationManagerImpl implements WsjDelRelationManager{
	
	@Autowired
	private WsjDelRelationDao wsjDelRelationDao;
	
	/**
	 * @category 获取配送企业列表 给wsj申报
	 * @author wangbing
	 * @date   2015-11-20 10:49:39
	 * @param  @param page
	 * @param  @return Pagination
	 */
	@Override
	public Pagination getDelCompList(Pagination page) {
		return wsjDelRelationDao.getDelCompList(page);
	}
	
	/**
	 * 
	 *@category wsj 申报配送企业 
	 *@author wangbing
	 *@date 2015-11-20 10:45:29
	 *@param page
	 *@return Pagination
	 */
	@Transactional
	@Override
	public int declareDelComp(List<Map<String,String>> list){
		return wsjDelRelationDao.declareDelComp(list);
	}
	
	/**
	 * 
	 *@category wsj 获取遴选结果列表
	 *@author wangbing
	 *@date 2015-11-20 10:45:29
	 *@param 
	 *@return Pagination
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Pagination getSelectResultList(Pagination page){
		List<Map<String,Object>> list = (List<Map<String, Object>>) wsjDelRelationDao.getSelectResultList(page).getRows();
		for(Map<String,Object> data : list) {
			Object status = data.get("status");
			Object delRange = data.get("delRange");
			Object selDatetime = data.get("selDatetime");
			data.put("status", status==null?"": ConstantsUtil.selectRangeStatus(status.toString()));
			
			if (null == delRange || "".equals(delRange.toString())){
				data.put("delRange", "");
			} else {
				if (!"1".equals(status.toString())){
					if ("0".equals(delRange.toString())){
						data.put("delRange", ConstantsUtil.delRange(String.valueOf(Constants.DEL_RANGE_BASE)) + "，" + ConstantsUtil.delRange(String.valueOf(Constants.DEL_RANGE_COUNTY)));
					} else {
						data.put("delRange", ConstantsUtil.delRange(delRange.toString()));
					}
				} else {
					data.put("delRange", "");
				}
			}
			data.put("selDatetime", selDatetime==null?"":DateUtil.dateTime((Timestamp)selDatetime));
		}
		return page;
	}
}
